-- This script was generated by the Schema Diff utility in pgAdmin 4
-- For the circular dependencies, the order in which Schema Diff writes the objects is not very sophisticated
-- and may require manual changes to the script to ensure changes are applied in the correct order.
-- Please report an issue for any failure with the reproduction steps.

CREATE OR REPLACE VIEW public.model_metrics
 AS
 SELECT m.model,
    sum(m.total_tokens) AS sum_tokens
   FROM ( SELECT response.id,
            response.created_at,
            response.body,
            response.request,
            response.body ->> 'model'::text AS model,
            ((response.body -> 'usage'::text) ->> 'total_tokens'::text)::bigint AS total_tokens
           FROM response_rbac response) m
  GROUP BY m.model;

ALTER TABLE public.model_metrics
    OWNER TO postgres;

GRANT ALL ON TABLE public.model_metrics TO authenticated;
GRANT ALL ON TABLE public.model_metrics TO postgres;
GRANT ALL ON TABLE public.model_metrics TO anon;
GRANT ALL ON TABLE public.model_metrics TO service_role;
